//app.js
import WxValidate from 'utils/WxValidate'
const Utils = require('utils/util.js')
App({
  onLaunch: function () {
    console.log("app onLaunch myveiw");
    //调用API从本地缓存中获取数据
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
  },
  onShow: function () {
    console.log("app show myveiw");
  },
  onHide: function () {
    console.log("app hide myveiw");
  },
  //获取用户信息
  getUserInfo: function (cb) {
    var that = this
    if (this.globalData.userInfo) {
      typeof cb == "function" && cb(this.globalData.userInfo)
    } else {
      //调用登录接口
      wx.login({
        success: function (loginres) {
          that.globalData.code = loginres.code
          wx.getUserInfo({
            success: function (res) {
              that.globalData.encryptedData = res.encryptedData
              that.globalData.iv = res.iv
              that.userInfo = res.userInfo
              typeof cb == "function" && cb(that.globalData.userInfo)
            }
          })
        }
      })
    }
  },
  //全局参数
  globalData: {
    code: '',
    encryptedData: '',
    iv: '',
    sys_code: 'sdzfxndefx',
    appid: "wxbaa06d726bac00d8"
  },
  userInfo: null,
  ticketTags: {
    "onlyHoliday": "节假日开放",
    "onlyWeekend":"周末开放",
    "refundable":"支持退款",
    " onlyHoliday": "节假日开放",
    " onlyWeekend": "周末开放",
    " refundable": "支持退款"
  },
  //表单验证
  WxValidate: (rules, messages) => new WxValidate(rules, messages),
  addParams: function (params) {
    let that = this
    return Utils.json2Form(Object.assign(params, that.globalData))
  }
})